package cn.zhaoyuening.hnistalumnirecord.dao.impl;

import cn.zhaoyuening.hnistalumnirecord.dao.NewsDao;
import cn.zhaoyuening.hnistalumnirecord.domain.News;
import com.mysql.jdbc.StringUtils;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.List;

/**
 * Created by zhao on 17-1-17.
 */
@Repository
public class NewsDaoImpl extends BaseDaoImpl<News> implements NewsDao {
    @Override
    public long getTotalRecordByModuleId(Serializable id) {
        String hql = "select count(*) from " + getEntityClass().getName() + "  where moduleId = "+id;
        List list = getHibernateTemplate().find(hql);
        long totalRecord = (Long) list.get(0);
        return totalRecord;
    }

    @Override
    public long getTotalRecordByModuleIdAndTitle(Serializable id, String title) {
        String hql = "select count(*) from " + getEntityClass().getName() + "  where moduleId = "+id;
        if (!StringUtils.isNullOrEmpty(title)) {
            hql += "and title LIKE '%"+title+"%'";
        }
        List list = getHibernateTemplate().find(hql);
        long totalRecord = (Long) list.get(0);
        return totalRecord;
    }
}
